# model

# responsible for various checks and actions, when octopus is started
# e.g. 
#    is the user already logged in?
#    which language is chosen?
#    are already entered credentials?
#    logout-process


from google.appengine.ext import webapp

#from google.appengine._internal.django.utils.translation import ugettext as _

#from google.appengine._internal.django.utils.translation import ugettext_lazy as _

from Utilities import *
from controller.BuildMainPage import *


class MainPage(webapp.RequestHandler):  
    def get(self):
        utilities = Utilities()

        username = utilities.getUsername()
        userText = utilities.getUserText()
            
        # check if there is an user logged-in        
        if username:
            urlText = utilities.getUrlTextLogout()
            url = utilities.getLogout(self)
            hintText = ''
            hintColor = 'black'
            
            # check for credentials
            credentials = utilities.getCredentials(username)
            results = credentials.fetch(100)
            if not results:
#                hintText = _('Now, you need to configure your Credentials!')
                hintText = 'Now, you need to configure your Credentials!'
                hintColor = 'red'
            else:
                hintText = ''
                hintColor = 'black'
        else:
            urlText = utilities.getUrlTextLogin()
            url = utilities.getLogin(self)
            username = '-------'
            hintText = utilities.getHintTextFirstLogin()
            hintColor = 'red'
            
        # call the builder-page (controller) to form the html-tags.
        # params:    all necessary attributes to fill the place-holder
        builder = BuildMainPage()
        
        templateValues = {
                          'user': username,
                          'userText': userText,
                          'url': url,
                          'urlText': urlText,
                          'hintText': hintText,
                          'hintColor': hintColor
                          }
        
        builder.get(self, templateValues)


